package com.qiqidream.admin.tools.api;

import com.qiqidream.admin.common.base.BaseController;
import com.qiqidream.admin.tools.model.entity.SysSetting;
import com.qiqidream.admin.tools.model.vo.LoadingSettingVo;
import com.qiqidream.admin.tools.service.SysSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.toMap;


/**
 * @author QiQiDream
 * @since 2020/1/5 15:22
 */
@RestController
@Api(tags = "系统工具-设置接口")
@RequestMapping("/tools/setting")
public class SysSettingController extends BaseController {
    @Resource
    SysSettingService sysSettingService;

    @ApiOperation(value = "获取系统配置（在登录页加载系统设置）")
    @GetMapping("/loading")
    public Map<String, LoadingSettingVo> getSetting() {
        List<SysSetting> list = sysSettingService.list();
        return list.stream().collect(toMap(SysSetting::getCode,data -> new LoadingSettingVo(data.getEnabled(),data.getConfig())));
    }
}
